﻿// oprate.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
/*
运算符重载 测试
函数开头的 const 用来修饰函数的返回值，表示返回值是 const 类型，也就是不能被修改，例如const char * getname()。
函数头部的结尾加上 const 表示常成员函数，这种函数只能读取成员变量的值，而不能修改成员变量的值，例如char * getname() const。
*/

class complex {
public:
    complex();
    complex(double real, double imag);

    complex operator+(const complex& A) const;
    void display() const;
private:
    double m_real;
    double m_imag;
};
//构造函数

complex::complex() :m_real(0.0), m_imag(0.0) {

}

complex::complex(double real, double imag) : m_real(real), m_imag(imag) {}

//实现运算符重载
complex complex::operator+(const complex& A) const {
    complex B;
    B.m_real = this->m_real + A.m_real;
    B.m_imag = this->m_imag + A.m_imag;
    return B;
}

/*
运算符重载 []
*/
class Array {
public:
    Array(int length);
    ~Array();

    int& operator[](int i);
    const int& operator[](int i) const;

    int length() const {
        return m_length;
    }

    void display() const;

private:
    int m_length; //数组长度
    int* m_p; //指向数组内存的指针
};
Array::Array(int length) :m_length(length) {
    if (length == 0)
    {
        m_p = NULL;
    }
    else
    {
        m_p = new int[length];
    }
}
Array::~Array() {
    delete[] m_p;
}

int& Array::operator[](int i) {
    return m_p[i];
}
const int& Array::operator[](int i) const {
    return m_p[i];
}

void Array::display() const {
    for (size_t i = 0; i < m_length; i++)
    {
        if (i == m_length - 1)
        {
            std::cout << m_p[i] << std::endl;
        }
        else
        {
            std::cout << m_p[i] << ", ";
        }
    }
}


void complex::display() const {
    std::cout << m_real << " " << m_imag << "i" << std::endl;
}
int main()
{
    /*
    complex c1(4.3, 5.6);
    complex c2(2.5, 4.1);
    complex c3;
    c3 = c2 + c1;
    c3.display();
    std::c
    out << "Hello World!\n";
    */
    int n;
    std::cin >> n;
    Array array(n);
    for (size_t i = 0,len = array.length(); i < len; i++)
    {
        array[i] = i * 5;
    }
    array.display();
    
    const Array B(n);
    std::cout << B[n - 1] << std::endl;

    return 0;
}


